package sim.tests.games.sailing;

import java.nio.FloatBuffer;

import sim.Image;
import sim.Sound;
import sim.misc.Holder;
import sim.states.BasicGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.BufferUtils;

public class Test extends BasicGame
{
	Image image;
	sim.Sound sound;
	float dx = 0;
	float dy = 0;
	float x;
	float y;
	Mesh mesh;
	Boat boat;

	@Override
	public void init()
	{
		// Gdx.input.setCursorCatched(true);
		setWorldSize(10, 6);
		camera.translate(camera.viewportWidth / 2, camera.viewportHeight, 0);
		image = new Image("crate.png");
		image.setSize(1, 1);
		x = 5;
		y = 5;
		boat = new Boat(0, 0);

		mesh = new Mesh(true, 3, 3, new VertexAttribute(Usage.Position, 3,
				"a_position"));
		mesh.setIndices(new short[] { 0, 1, 2 });
		mesh.setVertices(new float[] { -5f, -5f, 0, 5f, -5f, 0, 0, 5f, 0 });

		Gdx.gl.glEnable(GL10.GL_LIGHTING);

		// Enable up to n=8 light sources: GL_LIGHTn
		//Gdx.gl.glEnable(GL10.GL_LIGHT0);
		//Gdx.gl.glEnable(GL10.GL_LIGHT1);
		//Gdx.gl.glEnable(GL10.GL_LIGHT2);
		Gdx.gl.glEnable(GL10.GL_LIGHT3);
		//Gdx.gl.glEnable(GL10.GL_LIGHT4);
		/*
		// Light position
		Gdx.gl11.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, new float[] { 0,
				0, 1, 1 }, 0);
		// Light that has been reflected by other objects and hits the mesh in
		// small amounts
		Gdx.gl11.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, new float[] {
				0.005f, 0.005f, 0.005f, 1f }, 0);

		// setting diffuse light colour like a bulb or neon tube
		Gdx.gl11.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, new float[] { 0.9f,
				0.9f, 0.7f, 1f }, 0);

		// setting specular light color like a halogen spot
		Gdx.gl11.glLightfv(GL10.GL_LIGHT2, GL10.GL_SPECULAR, new float[] {
				0.9f, 0.9f, 0.7f, 1f }, 0);
*/
		// directional or positional light
		 // vector4f is x,y,z + w component
		 // w=0 to create a directional light (x,y,z is the light direction) like the sun
		 // w=1 to create a positional light like a fireball.
		 FloatBuffer fb = BufferUtils.newFloatBuffer(8);
		 fb.put(new float[]{1, 1, 0, 1});
		 Gdx.gl11.glLightfv(GL10.GL_LIGHT3, GL10.GL_POSITION, fb);
		 
		
		
	}

	@Override
	public void draw()
	{

		mesh.render(GL10.GL_TRIANGLES, 0, 3);
		boat.draw();
		

	}

	@Override
	public void update(float delta)
	{

		boat.update(delta);
		camera.position.x = boat.x;
		camera.position.y = boat.y;

	}
}
